package demo1;

public class StringTest {
    public static void main(String[] args) {
        //test1();
        //test2();
        //test3();
        //test4();
        //test5();
        //test6();
        //test7();
        //test8();
        test9();
    }
    public static void test9() {
        String name = "    zhang san    ";
        System.out.println(name.trim());
    }
    public static void test8() {
        String name = "zhangsan";
        System.out.println(name.substring(5));
        System.out.println(name.substring(5,8));
        System.out.println(name.subSequence(5,8));
    }
    public static void test7() {
        String str = "2025\\3\\24+2025";
        String[] string = str.split("\\\\|\\+");
        for (String s:string) {
            System.out.println(s);
        }
    }
    public static void test6() {
        String str = "1 + 3 = 2 + 2";
        String[] string = str.split("\\+");
        for (String s:string) {
            System.out.println(s);
        }
    }
    public static void test5() {
        String str = "Hello word Java";
        String[] string = str.split(" ");
        for (String s:string) {
            System.out.println(s);
        }
        System.out.println("---------");
        String[] string1 = str.split(" ",10);
        for (String s:string1) {
            System.out.println(s);
        }
        System.out.println("---------");
        String[] string2 = str.split(" ",2);
        for (String s:string2) {
            System.out.println(s);
        }
    }
    public static void test4() {
        String name = "张三丰";
        System.out.println(name.replace('张', '李'));
        System.out.println(name.replace("张三", "李四"));
        String str = "ab_cd_ab";
        System.out.println(str.replaceAll("ab", "hahaha"));
        System.out.println(str.replaceFirst("ab", "hahaha"));
    }
    public static void test3() {
        String date = String.format("%d/%d/%d",2025,3,24);
        System.out.println(date);
    }
    public static void test2() {
        String name = "zhangsan";
        char[] chars = name.toCharArray();
        for (char ch:chars) {
            System.out.print(ch);
        }
        System.out.println();
        String str = new String(chars);
        System.out.println(str);
    }
    public static void test1() {
        String name = "WorD";
        System.out.println(name.toLowerCase());
        System.out.println(name);
        System.out.println(name.toUpperCase());
        System.out.println(name);
    }
}
